package com.cjy.service.user.impl;

import com.cjy.mapper.user.UserMapper;
import com.cjy.entity.user.UserEntity;
import com.cjy.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjy.common.utils.StringUtils;
import com.cjy.common.message.RequestPageHead;
import com.cjy.common.message.BaseResult;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;


/**
 * @Description 服务实现类
 * @Author chengjiye
 * @Date 2020-11-12 13:42
 */
@SuppressWarnings("ALL")
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements IUserService {

    @Autowired
    private UserMapper modelMapper;

    /**
     * 列表查询
     *
     * @return
     */
    @Override
    public List<UserEntity> queryUserEntityList(RequestPageHead req) {
        BaseResult.startPage(req);
        List<UserEntity> list = modelMapper.queryUserEntityList(req);
        if (CollectionUtils.isEmpty(list)) {
            list = new ArrayList<>();
        }
        return list;
    }


    /**
     * 按id查询详情
     *
     * @param reqDetail 查询参数
     * @return
     */
    @Override
    public UserEntity queryUserEntityById(UserEntity reqDetail) {
        UserEntity entity = modelMapper.selectById(reqDetail.getId());
        if (StringUtils.isBlank(entity)) {
            return new UserEntity();
        }
        return entity;
    }


    /**
     * 添加
     *
     * @param reqAdd 实体对象
     * @return
     */
    @Override
    public Integer insertUserEntity(UserEntity reqAdd) {
        return modelMapper.insert(reqAdd);
    }


    /**
     * 按id进行物理删除，谨慎操作
     *
     * @param reqDelete 查询参数
     * @return
     */
    @Override
    public Integer deleteUserEntityById(UserEntity reqDelete) {
        return modelMapper.deleteById(reqDelete.getId());
    }


    /**
     * 按id修改
     *
     * @param reqEdit 实体对象
     * @return
     */
    @Override
    public Integer updateUserEntityById(UserEntity reqEdit) {
        return modelMapper.updateById(reqEdit);
    }
}
